package com.example.mywechat.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.mywechat.R;

/**
 * create an instance of this fragment.
 */
public class HomeFragment extends Fragment {

    private static final String ARG_TEXT = "param1";

    private String mTextString;

    private View rootView;

    public HomeFragment() {
        // Required empty public constructor
    }

    /**
     * 使用此工厂方法创建HomeFragment的实例
     * @param param1 参数1
     * @return HomeFragment的实例
     */
    public static HomeFragment newInstance(String param1) {
        HomeFragment homeFragment = new HomeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_TEXT, param1);

        homeFragment.setArguments(args);
        return homeFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mTextString = getArguments().getString(ARG_TEXT);
        }
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.fragment_home, container, false);
        }

        initView();

        return rootView;
    }

    private void initView() {
        TextView tvTitle = rootView.findViewById(R.id.tv_title);
        tvTitle.setText(mTextString);
    }
}